package com.hucheng.activity.entity;

import com.hucheng.activity.dto.UserPointDTO;
import com.hucheng.activity.dto.UserPointDetailsDTO;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.sql.Timestamp;
import java.util.Date;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-07-10
 * @Description: 持久层数据
 **/
@Data
public class UserPointDetailsDO {
    private Integer userPointDetailsId;
    private Integer point;
    private Integer userId;
    private Integer pointType;
    private String source;
    private Date expiredTime;
    private Integer isDel;
    private Timestamp dateCreated;
    private Timestamp dateUpdated;

    public static UserPointDetailsDO buildUserPointDetailsDO(final UserPointDetailsDTO userPointDetailsDTO) {
        if (userPointDetailsDTO != null) {
            UserPointDetailsDO userPointDetailsDO = new UserPointDetailsDO();
            Timestamp currentTime = new Timestamp(System.currentTimeMillis());
            if (StringUtils.isNotEmpty(userPointDetailsDTO.getUserPointDetailsId()+"")) {
                userPointDetailsDO.setUserPointDetailsId(userPointDetailsDTO.getUserPointDetailsId());
                userPointDetailsDO.setDateCreated(currentTime);
            }else{
                userPointDetailsDO.setDateUpdated(currentTime);
            }
            userPointDetailsDO.setPoint(userPointDetailsDTO.getPoint());
            userPointDetailsDO.setUserId(userPointDetailsDTO.getUserId());
            userPointDetailsDO.setPointType(userPointDetailsDTO.getPointType());
            userPointDetailsDO.setSource(userPointDetailsDTO.getSource());
            userPointDetailsDO.setExpiredTime(userPointDetailsDTO.getExpiredTime());
            userPointDetailsDO.setIsDel(userPointDetailsDTO.getIsDel());
            return userPointDetailsDO;
        }
        return null;
    }
}
